import java.util.*;
public class Solution {
    public int MoreThanHalfNum_Solution(int [] array) {
        int n = array.length;
        int half = n/2;
        Map<Integer,Integer> map = new HashMap<>();
        for(int k : array){
            int count = map.getOrDefault(k,0);
            map.put(k,count+1);
            if(map.get(k) > half){
                return k;
            }
        }
        return -1;
    }
}

